package com.utils;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

public class UploadUtils {

    public static String uploadFile(MultipartFile file) {
        String pathName = "";
        try {
            // 写入本地文件
            pathName = "D:\\student\\upload\\" + file.getOriginalFilename();
            File localFile = new File(pathName);
            file.transferTo(localFile);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        String resultPath = "http://localhost:8080/img/" + file.getOriginalFilename();
        return resultPath;
    }

}
